/**
 * 8080a emulator by triton & ic
 *
 * CPU header
 */

#define DEBUG

#define  LOWENDIAN
/* #define  BIGENDIAN */

#ifndef __8080A_H__
#define __8080A_H__

#include <inttypes.h>

typedef uint8_t byte;
typedef uint16_t word;

/*
#ifdef LOWENDIAN
    #warning TODO
#else
    #warning Please define endianness!
#endif
*/

#define pair(A, B) \
    union {        \
        word pair; \
        struct { byte A, B; } reg; \
    } A ## B;

typedef struct
{
    pair(A, F)
    pair(B, C)
    pair(D, E)
    pair(H, L)
    word SP, PC, IR;
    byte I, R;
    int cycles;
} EEctx;

#define RAMSIZE 0x10000
byte RAM[RAMSIZE];

#define S_FLAG    0x80
#define Z_FLAG    0x40
#define AC_FLAG   0x10
#define P_FLAG    0x04
#define V_FLAG    P_FLAG
#define N_FLAG    0x02
#define C_FLAG    0x01

void peekRAM(int lim);
void reset8080a(EEctx *R);
void exec8080a(EEctx *R, int cycles);

#ifdef DEBUG
void debug8080a(EEctx *R);
#endif

#endif
